package com.qf.controller;

import com.qf.entity.Dept;
import com.qf.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * User: key
 * ClassName:DeptController
 * Date: 2023/5/27
 * Time: 14:27
 * description:
 */
@Controller
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping("/deptList")
    public String deptList(Model model) {
        List<Dept> depts = deptService.selectDept();
        model.addAttribute("deptList", depts);
        return "dept/deptList";
    }

    @RequestMapping("/deptMsg")
    public String deptMsg() {
        return "dept/addDept";
    }

    @RequestMapping("/addDept")
    public String addDept(Dept dept) {
        deptService.addDept(dept);
        return "redirect:deptList";
    }

    @RequestMapping(value = "/deleteDept", method = RequestMethod.GET)
    public String deleteDept(@RequestParam(value = "dno", required = false, defaultValue = "1") Integer dno) {
        deptService.deleteDept(dno);
        return "redirect:deptList";
    }
}
